package com.xunwulian.web.entity;

import com.xunwulian.base.constant.BillStatus;
import com.xunwulian.base.entity.BillEntity;
import com.xunwulian.base.util.DateStyle;
import com.xunwulian.base.util.DateUtil;
import com.xunwulian.base.util.EnumUtils;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;

public class BillEntityWrapper extends BillEntity {

    private String billDateStr;

    private String statusStr;

    public BillEntityWrapper() {

    }

    public BillEntityWrapper(String billDateStr,
                             String statusStr) {
        this.billDateStr = billDateStr;
        this.statusStr = statusStr;
        setAmt(new Double(0));
        setPaidAmt(new Double(0));
        setOverDueDays(new Integer(0));
    }

    public BillEntityWrapper(BillEntity entity) {

        try {
            ConvertUtils.register(new DateConverter(null), java.util.Date.class);

            BeanUtils.copyProperties(this, entity);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        this.statusStr = BillStatus.UNKNOWN.getDesc();
        BillStatus billStatus = EnumUtils.getEnumByType(BillStatus.class, entity.getStatus());
        if (billStatus != null) {
            statusStr = billStatus.getDesc();
        }

        this.billDateStr = DateUtil.DateToString(getBillDate(), DateStyle.YYYY_MM_CN);
    }

    public String getStatusStr() {
        return statusStr;
    }

    public void setStatusStr(String statusStr) {
        this.statusStr = statusStr;
    }

    public String getBillDateStr() {
        return billDateStr;
    }

    public void setBillDateStr(String billDateStr) {
        this.billDateStr = billDateStr;
    }
}
